package utils;

import java.io.*;

public class CSVTool {
    public static void main(String[] args) {
        String str = "pname1,123.2";

        Long startTime = System.currentTimeMillis();

        for(int i = 0; i < 1000000; i++){
            try{
                write2File(str);
            }catch (IOException e){
                e.printStackTrace();
            }
        }

        Long endTime = System.currentTimeMillis();

        System.out.println("执行时间:" + (endTime-startTime));
    }

    public static void write2File(String str) throws IOException {
        File f = new File("D:\\222.csv");
        if (!f.exists()) {
            System.out.print("文件不存在");
            // 不存在则创建
            if(f.createNewFile()){
                System.out.print("文件创建成功");
            }
        }

        //true,则追加写入text文本
        BufferedWriter output = new BufferedWriter(new FileWriter(f,true));

        output.write(str);
        output.write("\r\n");
        output.flush();
        output.close();
    }
}
